********************************************************************************
** Covid-19 Crisis and Hostility against Foreigners master file
*******************************************************************************

*The authors ask researchers who plan to use this data set to inform the corresponding authors (bauer@cerge-ei.cz; chytilova@fsv.cuni.cz) about the purpose of their planned research.

*******************************************************************************
* Data, codes and all related files are available in the Harvard Depository>
*https://doi.org/10.7910/DVN/XD8OOL

*******************************************************************************
* Version history and a note on a labeling error in version 1-3

* 21.6.2021 Version 5 Vojtech Bartos and Jana Cahlikova
* 17.6.2020 Version 4 Vojtech Bartos and Jana Cahlikova
* 30.5.2020 Version 3 Vojtech Bartos and Jana Cahlikova
* 18.5.2020 Version 2 Vojtech Bartos and Jana Cahlikova
* 30.4.2020 Version 1 Vojtech Bartos and Jana Cahlikova

* !!! Labeling error in a preliminary version of the manuscript (versions 1-3 of the dataset) !!!
* Please note that Version 1-Version 3 of the dataset included a labeling error that was reported to us by the survey company on June 10, 2020. The error has been corrected in the version 4 of the dataset. 
*The error was caused by the survey programmer erroneously numbering three questions in the Help-or-Harm task. The error occurred only in the CONTROL condition. The labeling was correct in the treatment (COVID-19) condition. This mislabeling resulted in the following: 
*1.	The reward allocated to a recipient living in the Czech Republic without religious denomination was labeled as a reward allocated to a person living in Asia.
*2.	The reward allocated to a person living in the Czech Republic with Christian denomination was labeled as a reward to a person living in the Czech Republic with no religious denomination.
*3.	The reward allocated to a person living in Asia was labeled as a reward to a person living in the Czech Republic with Christian denomination.
*The error was discovered by PAQ research and was reported to us on June 10, 2020. After making sure the dataset was corrected and accurate, we re-ran the analysis using the corrected dataset and made changes in the paper reflecting the changes in the results. The estimates for the following outcome variables were affected: Asian, foreign, domestic in-group, domestic out-group, religion in-group, religion out-group. Estimates for other outcome variables were not affected by the error. For more details, see Supplementary Information section 1.7.
*The nature of the mistake and the time when it was discovered and shared with us has been acknowledged and described in detail in a letter by the director of PAQ research, Daniel Prokop. Further, to ensure accuracy of the question numbering in the corrected (version 4) dataset, an independent audit of the data was conducted by Martin Buchtík, the director of STEM, a major survey agency based in the Czech Republic. His audit confirmed that this was the only error in the raw data that we received for our analysis. The letter from Daniel Prokop and the statement of Martin Buchtík are both available in our data repository at Harvard Dataverse, available at https://doi.org/10.7910/DVN/XD8OOL. 

*******************************************************************************
* Currently programmed for Stata 16
* For an earlier version, change number accordingly in the following:
version 16

*******************************************************************************
clear all
set more off
global date 200326
set seed 840801
* installs lean2 scheme if not already installed
capture findfile lean2.scheme 	
if _rc==601 {
	net install gr0002_3, from(http://www.stata-journal.com/software/sj4-3)
	}
set scheme lean2

** Set Directories *************************************************************

if "`c(username)'" == "vojtabartos" { 
	global dropbox "/Users/vojtabartos/Dropbox/CZ Covid and scapegoating/1_analysis/" 
	}
	
	if "`c(username)'" == "cahj" { 
	global dropbox "C:/Dropbox/CZ Covid/1_analysis" 
	}
	
	/* !!!! Others: use the code snippet to set your working directory: need to change your username & path
if "`c(username)'" == "vojtabartos" { 
	global dropbox "/Users/vojtabartos/Dropbox/CZ Covid and scapegoating/1_analysis/" 
	}	

!!! For the code to work, organize the folders in your working directories as follows
AND save all do files into $dropbox/2_do_files/covid_fuels_hostility
AND save all data files into $dropbox/1_clean_data
	
*/

global cleandatapath "$dropbox/1_clean_data"
global dopath "$dropbox/2_do_files/covid_fuels_hostility"
global logpath "$dropbox/3_log_files/covid_fuels_hostility"
global outputpath "$dropbox/4_output/covid_fuels_hostility"

** Datasets *************************************************************
*save them into "$dropbox/1_clean_data"

	**Main dataset in the wide format
		* use"$cleandatapath/covid_fuels_hostility_clean.dta", clear

	**Main dataset in the long format
		* use"$cleandatapath/covid_fuels_hostility_clean_long.dta", clear
		*is obtained by running: do "$dopath/01_data_reshape_wide_long"
	
	**Covid cases in the Czech Republic (Source: Czech Ministry of Health, https://onemocneni-aktualne.mzcr.cz/covid-19/; accessed on April 23, 2020)
		*use "$cleandatapath/covid_cases_CZ_by_date_MZCR.dta", clear
		*used only to create Supplementary Figure 4 


** Programs required ************************************************************

* All programs that need to be installed to be listed here together with install command (ssc install xxx)
*moremata sometimes giving error messages if already installed - in that case drop it in the next command
local required_ados "spmap shp2dta mif2dta distplot orth_out lincomest moremata somersd" //add the required ados here//
foreach x of local required_ados {
	capture findfile `x'.ado		
	if _rc==601 {
	ssc install `x'
	}
}
* If you are running the command for the first time and receive an error message claiming certain functions are not found, make sure that lmhtreg.mlib exists in your current dir and enter the command below: 
* mata: mata mlib index
capture findfile mhtreg.ado		
if _rc==601 {
	net install mhtreg, from(https://sites.google.com/site/andreassteinmayr/mhtreg)
	}
capture findfile grc1leg.ado		
if _rc==601 {
	net from http://www.stata.com
    net cd users
    net cd vwiggins
    net install grc1leg
}	



** General options *************************************************************

* e.g., global / local lists of variables to be defined here


global esttab_opt_stats "stats(N, fmt(0) labels("Observations"))"
global cells "compress b(%3.2f) se(%3.2f) star(* 0.10 ** 0.05 *** 0.01) noomit nobase drop(`covars')"
global tex "collabels(,none)"

* Ordering dummies (order Help-or-Harm task)
global x_d_order d_order_2 d_order_3 d_order_4 d_order_5 d_order_6 d_order_7 d_order_8 d_order_9 d_order_10 d_order_11 d_order_12 d_order_13 d_order_14 d_order_15 d_order_16 d_order_17 d_order_18 d_order_19 d_order_20 d_order_21 d_order_22 d_order_23 d_order_24 d_order_25 d_order_26 d_order_27 d_order_28 d_order_29 d_order_30 d_order_31 d_order_32 d_order_33 d_order_34 d_order_35 d_order_36 d_order_37 d_order_38 d_order_39 d_order_40 d_order_41 d_order_42 d_order_43 d_order_44 d_order_45 d_order_46 d_order_47 d_order_48 d_order_49 d_order_50 d_order_51 d_order_52 d_order_53 d_order_54 d_order_55 d_order_56 d_order_57 d_order_58 d_order_59 d_order_60 d_order_61 d_order_62 d_order_63 d_order_64 d_order_65 d_order_66 d_order_67 d_order_68 d_order_69 d_order_70 d_order_71 d_order_72 d_order_73 d_order_74 d_order_75 d_order_76 d_order_77 d_order_78 d_order_79 d_order_80 d_order_81 d_order_82 d_order_83 d_order_84 d_order_85 d_order_86 d_order_87 d_order_88 d_order_89 d_order_90 d_order_91 d_order_92 d_order_93 d_order_94 d_order_95 d_order_96

* Baseline controls
global basic_controls female d_age_cat2 d_age_cat3 d_age_cat4 d_age_cat5 d_age_cat6 hsize children d_region2 d_region3 d_region4 d_region5 d_region6 d_region7 d_region8 d_region9 d_region10 d_region11 d_region12 d_region13 d_region14 d_townsize2 d_townsize3 d_townsize4 d_townsize5 d_townsize6 d_townsize7 d_educ2 d_educ3 d_educ4 d_estat2 d_estat3 d_estat4 d_estat5 d_estat6 d_estat7 d_CNP_hincome2 d_CNP_hincome3 d_CNP_hincome4 d_CNP_hincome5 d_CNP_hincome6 d_CNP_hincome7 d_CNP_hincome8 d_CNP_hincome9 d_CNP_hincome10 d_CNP_hincome11 $x_d_order

* Additional controls
global additional_controls job_loss payment_problems sav_monthandless sav_weeks happiness dep_anx pss4 nQ55_0_0 nQ55_1_0 nQ55_2_0 nQ55_3_0 nQ55_4_0 nQ55_5_0 nQ55_6_0 nQ55_7_0 traveled traveled_hh know_covid know_covid_hh know_quarantine activities_w1 activities_hh_w1 not_working_w1 not_meeting_anyone_w1 activities_w2 activities_hh_w2 not_working_w2 not_meeting_anyone_w2 preventive_measures tested tested_hh symptoms contact_medical health_issue_hh

label define yes_no 0 "No" 1 "Yes"

** Run files *******************************************************************
* This part runs all do files from the raw data cleaning all the way to producing final output (tables, figures, statistics)

* 1. Reshaping the dataset from wide to long
do "$dopath/01_data_reshape_wide_long"

* 2. Analysis: Tables
do "$dopath/02_tables"

* 3. Analysis: Figures
do "$dopath/03_figures"

* 4. Analysis: Multiple hypothesis testing (extremely long processing time)
*do "$dopath/04_mht"

* 5. Analysis: Tests in text 
do "$dopath/05_tests_in_text" 
